package com.stu.design_patterns.singleton;

public class Singleton04StaticInnerClass {
  private Singleton04StaticInnerClass() {}
  // 2、由于静态内部类不会随着外围类的加载而加载，所以将 singleton 放在静态内部类中，天然就是懒加载的
  private static class SingletonHolder {
    // 1、类加载机制，天然线程安全，所以getInstance不用加锁，执行效率高
    private static Singleton04StaticInnerClass singleton = new Singleton04StaticInnerClass();
  }
  public static Singleton04StaticInnerClass getInstance() {
    return SingletonHolder.singleton;
  }
  public void say() { System.out.println("静态内部类式"); }
}
